package cn.crm.service.impl;

import java.util.List;
import javax.annotation.Resource;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.stereotype.Service;
import cn.crm.bean.Province;
import cn.crm.dao.ProvinceDao;
import cn.crm.service.ProvinceService;
@Service("provinceService")
public class ProvinceServiceImpl implements ProvinceService {

	@Resource
	private ProvinceDao provinceDao;
	@Override
	public List<Province> getAll() {
		return provinceDao.getAll();
	}

	@Override
	public List<Province> getAllByParentId(Integer id) {
		return provinceDao.getAllByParentId(id);
	}

	public void setProvinceDao(ProvinceDao provinceDao) {
		this.provinceDao = provinceDao;
	}

	@Override
	public String getJSONByParentId(Integer id) {
		JSONArray jlist=new JSONArray();
		List<Province> list=provinceDao.getAllByParentId(id);
		for (Province province : list) {
			JSONObject obj=new JSONObject();
			obj.put("id", province.getProCodeid());
			obj.put("name", province.getProCityname());
			jlist.add(obj);
		}
		return jlist.toJSONString();
	}

	@Override
	public Province getById(Integer id) {
		return provinceDao.getById(id);
	}

	
}
